<?php

class Simple_input_display extends CI_Controller {

	public function __construct() {
		parent::__construct(); 
                // the tutorial shows this as 
                // parent::Controller();
                
                $this->load->helper(array('form','url'));
                $this->load->library('form_validation');
	}
        
        public function index() {
		$this->load->view('testing/simple_input_display_view');
        }
        
        public function submit() {
            
            if ($this->_submit_validate() === FALSE) {
                $this->index();
                return;    
            }
            
            //$data['firstname'] = $user->getFirstName();
            $data = array();
            $data['message'] = "variable 'message' from the view,";
            
            $user = new Entities\User;
                $user->setFirstName('Bobby');
                $user->setLastName('Brown');
            
            $this->load->view('testing/simple_input_display_view2', $data);
        }
        
        private function _submit_validate() {
            
            $this->form_validation->set_rules('firstname', 'Firstname',
                    'required|alpha_numeric|min_length[4]|max_length[12]');
            
            $this->form_validation->set_rules('lastname', 'Lastname',
                    'required|alpha_numeric|min_length[4]|max_length[12]');
            
            return $this->form_validation->run();
        }
}
        ?>